package www.bancodelanacion.intranet.prestamos.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import www.bancodelanacion.intranet.prestamos.entidad.AuditoriaDTO;
import www.bancodelanacion.intranet.prestamos.util.MySqlDBConn;

public class AuditoriaDaoImpl implements AuditoriaDao{

	@Override
	public int registrar(AuditoriaDTO auditoriaDTO) throws SQLException {
		Connection conn = null;
		PreparedStatement pstm = null;
		try {
				conn = new MySqlDBConn().getConnection();
				String sql ="insert into tb_auditoria values(null,?,?,?)";
				pstm = conn.prepareStatement(sql);
				pstm.setString(1,auditoriaDTO.getFechaLogin());
				pstm.setString(2,auditoriaDTO.getFechaLogout());
				pstm.setString(3,auditoriaDTO.getTrabajador());
				return pstm.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(pstm!= null)pstm.close();
				if(conn!= null)conn.close();
			} catch (Exception e2) {}
		}
		return -1;
	}

	@Override
	public int update(AuditoriaDTO auditoriaDTO) throws SQLException {
		Connection conn = null;
		PreparedStatement pstm = null;
		try {
				conn = new MySqlDBConn().getConnection();
				String sql ="update tb_auditoria set fecha_logout=? " +
						     " where fecha_login=?";
				pstm = conn.prepareStatement(sql);
				pstm.setString(1,auditoriaDTO.getFechaLogout());
				pstm.setString(2,auditoriaDTO.getFechaLogin());
				return pstm.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(pstm!= null)pstm.close();
				if(conn!= null)conn.close();
			} catch (Exception e2) {}
		}
		return -1;
	}

}
